package com.crm.business.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.servlet.ServletUtil;
import com.alibaba.fastjson.JSONObject;
import com.crm.business.admin.log.AdminUserLog;
import com.crm.business.admin.service.*;
import com.crm.business.utils.UserCacheUtil;
import com.crm.business.utils.UserUtil;
import com.crm.common.admin.common.AdminCodeEnum;
import com.crm.common.admin.entity.BO.*;
import com.crm.common.admin.entity.PO.AdminAddressBook;
import com.crm.common.admin.entity.PO.AdminConfig;
import com.crm.common.admin.entity.PO.AdminUser;
import com.crm.common.admin.entity.PO.AdminUserConfig;
import com.crm.common.admin.entity.VO.AdminSuperUserVo;
import com.crm.common.admin.entity.VO.AdminUserVO;
import com.crm.common.admin.entity.VO.HrmSimpleUserVO;
import com.crm.common.auth.common.AuthorizationCodeEnum;
import com.crm.common.ka.core.common.*;
import com.crm.common.ka.core.common.log.BehaviorEnum;
import com.crm.common.ka.core.common.log.SysLog;
import com.crm.common.ka.core.common.log.SysLogHandler;
import com.crm.common.ka.core.entity.BasePage;
import com.crm.common.ka.core.entity.UserInfo;
import com.crm.common.ka.core.feign.admin.entity.SimpleRole;
import com.crm.common.ka.core.feign.admin.entity.SimpleUser;
import com.crm.common.ka.core.servlet.upload.UploadEntity;
import com.crm.common.utils.spring.SpringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 通讯录表 前端控制器
 * </p>
 *
 * @author zhangzhiwei
 * @since 2020-04-27
 */
@RestController
@RequestMapping("/adminAddressBook")
@Api(tags = "通讯录相关接口")
@Slf4j
public class AdminAddressBookController {

    @Autowired
    private IAdminAddressBookService adminAddressBookService;
    @Autowired
    private IAdminFileService adminFileService;

    @ApiOperation("通过条件分页查询员工列表")
    @PostMapping("/queryUserList")
    public Result<BasePage<AdminAddressBook>> queryUserList(@RequestBody AdminAddressBookBO adminUserBO) {
        return R.ok(adminAddressBookService.queryUserList(adminUserBO));
    }

    @PostMapping("/synchronousAddressBook")
    public Result synchronousAddressBook(){
        adminAddressBookService.synchronousAddressBook();
        return R.ok();
    }

    @PostMapping("/updateImg")
    @ApiOperation("上传微信二维码")
    @SysLogHandler(behavior = BehaviorEnum.UPDATE,object = "修改头像",detail = "修改头像")
    public Result updateImg(@RequestParam("file") MultipartFile file) throws IOException {
        UploadEntity img = adminFileService.upload(file, null, "img", "0");
        return R.ok(img);
    }

}

